/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pennychecker.swing.presenter.ext.component;

import com.pennychecker.swing.mvp.event.HandlerRegistration;
import com.pennychecker.swing.mvp.event.MvpEvent;
import com.pennychecker.swing.presenter.ext.event.ClickEvent;
import com.pennychecker.swing.presenter.ext.event.ClickHandler;
import com.pennychecker.swing.presenter.ext.event.HasClickHandlers;
import com.toedter.calendar.JDateChooser;
import java.beans.PropertyChangeEvent;

/**
 *
 * @author iolaus
 */
public class DateChooser extends JDateChooser implements HasClickHandlers {

    private static final long serialVersionUID = 1L;
    private final HandlerAdapter handlerAdapter = new HandlerAdapter();

    @Override
    public void propertyChange(PropertyChangeEvent e) {
        super.propertyChange(e);
        if (null != handlerAdapter && e.getPropertyName().equals("date")) {
            fireEvent(new ClickEvent());
        }

        // sonstige Impl
    }

    @Override
    public HandlerRegistration addClickHandler(ClickHandler handler) {
        return handlerAdapter.addHandler(handler, ClickEvent.TYPE);
    }

    @Override
    public void fireEvent(MvpEvent<?> event) {
        handlerAdapter.fireEvent(event);
    }
}
